package com.pojo.testenmun;

import com.dao.OrderItemMapper;
import com.dao.OrderMapper;
import com.pojo.Order;
import com.pojo.OrderItem;
import com.pojo.OrderStatus;
import com.pojo.TableStatus;
import com.service.OrderItemsService;
import com.service.OrderService;
import com.service.StatisticsService;
import com.utils.DateUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class testtest {

    public TableStatus tableStatus;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderItemsService orderItemsService;

    @Autowired
    private OrderItemMapper orderItemMapper;

    @Autowired
    private StatisticsService statisticsService;

    @Test
    public void test2(){
        tableStatus = TableStatus.EMPTY;

        tableStatus = TableStatus.BOOKED;

        tableStatus = TableStatus.FULL;

        System.out.println(tableStatus);
        System.out.println(tableStatus.toString());
        System.out.println(tableStatus.name());
        System.out.println(tableStatus.ordinal());

        TableStatus[] values = TableStatus.values();
        System.out.println(Arrays.toString(values));





    }

    @Test
    public void test3(){
//        EnumSet<TableStatus> set = new EnumSet<TableStatus>(){
//            @Override
//            public Iterator<TableStatus> iterator(){
//                return null;
//            }
//
//            @Override
//            public int size(){
//                return 0;
//            }
//        }
        EnumSet<TableStatus> set =  EnumSet.allOf(TableStatus.class);
        for(TableStatus tableStatus: set){
            System.out.println(tableStatus);
        }

        EnumMap<TableStatus, String> map = new EnumMap<>(TableStatus.class);
        map.put(TableStatus.BOOKED,"已预订");
        map.put(TableStatus.EMPTY,"空座");
        map.put(TableStatus.FULL,"已满");


        System.out.println(TableStatus.BOOKED+"啦啦啦");

        System.out.println();


    }

    @Test
    public void test5(){
        Random r = new Random();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        System.out.println("west-"+String.valueOf((simpleDateFormat.format(new Date())))+"-"+r.nextInt(1000));
        System.out.println("west-"+String.valueOf((Calendar.getInstance().getTime()))+"-"+r.nextInt(1000));

    }

    @Test
    public void test6(){
        System.out.println(OrderStatus.UNPAID.getStatus());
        Map<String, Object> map = new HashMap<>();
        map.put("status1", OrderStatus.SUSPENDED.getStatus());
        map.put("status2", OrderStatus.PAID.getStatus());
        map.put("tId", Integer.valueOf("1"));


        List<Order> list1 =  orderMapper.selectOrderWithStatusMap(map);
//        Order list1 = orderMapper.selectOrderWithItems(1);
//        for(Order order: list1){
            System.out.println(list1.get(0).getoDate()+"拉拉啊");
//        }
//        System.out.println(list1.get(0).getoDate()+"哈哈哈");
    }

    @Test
    public void test7(){

//
//        List<OrderItem> list1 = orderItemMapper.selectOrderItemByOid(1);
//
//        System.out.println(list1.get(0).getDish().getdName());
//        System.out.println(list1.get(0).getDish().getPrice());
        BigDecimal a = new BigDecimal("0.0");
//        Double b = a.doubleValue();
//        System.out.println(b);
        BigDecimal b = new BigDecimal("3.0");


        BigDecimal c = new BigDecimal("7.5");


        a = a.add(b);

        a = a.add(c);

        System.out.println(a);

    }

    @Test
    public void test9(){
//        ArrayList<String> currentWeekDays = new ArrayList<>();
//        for (int day=0; day<7 ; day++) {
//            Calendar calendar = Calendar.getInstance();
//            calendar.add(Calendar.DATE,-day);   // 日期从今天往前推
//            Date today = calendar.getTime();
//
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//            String date = format.format(today);
//
//
//
//            System.out.println("日期为："+date);
//
//            currentWeekDays.add(date);
//        }
//        List<String> a = statisticsService.getCurrentWeekDays();
//        for(String b: a){
//            System.out.println(b);
//        }

//        List<Order> a = orderMapper.selectAllByOrderStatus(OrderStatus.PAID.getStatus());
//        System.out.println(a.get(13).getoPayoffDate());
            Integer a = statisticsService.getFoodTypeStat(1);
            System.out.println("数量为：" + a);
    }

    @Test
    public void test10(){
        Map<String, Object> map = new HashMap<>();
        map.put("dishtypeId", 4);
        map.put("dateRangeFront", "2019-05-21 16:22:19");
        map.put("dateRangeEnd","2019-05-21 18:47:13");
        map.put("oStatus", OrderStatus.PAID.getStatus());

        List<Order> a = orderMapper.selectOrderByDateAndDishType(map);

        for(Order order: a){
            System.out.println(order.getoId());

        }
    }


    @Test
    public void test11(){

    }

}
